#pragma once
#include "../DirectX/stdafx.h"
#include <list>
#include "Vertex.h"
#include "Lines_Coords.h"

class Path
{
private:
	list<Vertex>		newPath,
						oldPath;

	float				sensativity_equals;

public:
	Path()
	{
		sensativity_equals	=	0.01f;
	}

	bool equals(list<Vertex>::iterator A, list<Vertex>::iterator B)
	{
		D3DXVECTOR2		alpha		= A->Dir_father - A->Dir_children,
						betha		= B->Dir_father - B->Dir_children;


		float			Theta_1		= abs(alpha.x - betha.x),
						Theta_2		= abs(alpha.y - betha.y);

		if ( Theta_1 < sensativity_equals && 
			 Theta_2 < sensativity_equals && 
			 equals(++A, *B) &&
			 equals(--A, *B))
			return true;
		else 
			return false;
	}

	bool equals(list<Vertex>::iterator A, Vertex B)
	{
		D3DXVECTOR2		alpha		= A->Dir_father - A->Dir_children,
						betha		= B.Dir_father - B.Dir_children;


		float			Theta_1		= abs(alpha.x - betha.x),
						Theta_2		= abs(alpha.y - betha.y);

		if(Theta_1 < sensativity_equals && Theta_2 < sensativity_equals)
			return true;
		else 
			return false;
	}

	void Update(Lines_Coords &Obj)
	{
		list<Vertex>::iterator	newPath_IT = newPath.begin(),
								oldPath_IT = oldPath.begin();

		for(int q=0; q<newPath.size(); q++)
		{
			bool	equals_newPath = false,
					equals_oldPath = false;

			for(int w=0; w<Obj.getCoords()->size(); w++)
			{
				if(equals(newPath_IT, Obj.getCoords()->at(w)))
					equals_newPath = true;

				if(equals(oldPath_IT, Obj.getCoords()->at(w)))
					equals_oldPath = true;
			}

			if(equals_newPath && equals_oldPath)
			{

			}
		}

		if(newPath.size() == 0)
		{
			for(int q=0; q < Obj.getCoords()->size(); q++)
				newPath.push_back(Obj.getCoords()->at(q));

			oldPath.clear();
		}
	}

	Vertex getPathPoint()
	{
		return *new POINT();
	}

};